<?php

namespace frontend\controllers;

use common\models\business\VideoBusiness;
use common\models\input\VideoSearch;
use Yii;

class VideoController extends BaseController {

    public function actionIndex() {

        $search = new VideoSearch();
        $search->setAttributes(Yii::$app->request->get());

        if ($search->pageSize == "" || $search->pageSize == null) {
            $search->pageSize = 6;
        }

        if ($search->page == "" || $search->page == null) {
            $search->page = 1;
        }
        $search->active = 1;
        $dataPage = $search->search(true);
        return $this->render("index", [
                    'dataPage' => $dataPage,
        ]);
    }

    public function actionDetail() {
        $id = Yii::$app->request->get('id');
        $detail = VideoBusiness::getWithImage($id);
        if (empty($detail)) {
            return $this->render('//error/message', ['message' => "Video không tồn tại", 'title' => "404 NOT FOUND"]);
        }
        $search = new VideoSearch();
        if ($search->pageSize == "" || $search->pageSize == null) {
            $search->pageSize = 6;
        }

        if ($search->page == "" || $search->page == null) {
            $search->page = 1;
        }
        $search->active = 1;
        $dataPage = $search->search(true);
        return $this->render("detail", [
        'detail' => $detail,
        'dataPage' => $dataPage,
        ]);
    }

}
